package 文件io;
import java.io.*;
/*
  复制的原理就是 
    从一个输入流读取数据，同时通过一个输出流输出到目标文件
  一句话就是 一面读一面写
*/

public class 简单的文件复制示例
{
	public static void main(String[] args){
		System.out.println("开始复制....");
		long start=System.currentTimeMillis();
		copy("/storage/emulated/0/Download/hqyl.mp","/storage/emulated/0/360/1.mp4");
		long end=System.currentTimeMillis();
		System.out.println("复制完成，用时: "+(end-start)+" 毫秒");
	}
	
	private static void copy(String src,String target){
		File srcFile=new File(src);
		File targetFile=new File(target);
		OutputStream out=null;
		InputStream in=null;
		
		try
		{
			in = new FileInputStream(srcFile);
			out = new FileOutputStream(targetFile);
			
			byte[] bytes=new byte[1024];
			int len=-1;
			while ((len=in.read(bytes))!=-1){
				out.write(bytes,0,len);
			}
		}
		catch (FileNotFoundException  e)
		{}
		catch(IOException e){}
		finally{
			try
			{
				if (in != null)in.close();
				if (out != null)out.close();
			}
			catch (IOException e)
			{}
		}
		
	}
}
